import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5 import uic
from Test import flir_camera
import numpy as np

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.ui = uic.loadUi('mainwindow.ui', self)
        # self.ui.setWindowTitle('uk')

        # print(self.graphicsView2.size())
        try:
            flir_camera.initSystem()
            print('系统初始化')
            self.visionCamera = flir_camera.Cam()
            print('相机初始化')
            self.visionCamera.imageArrived.connect(self.onReceiveImage)
            print('接收初始化')
            self.visionCamera.enableAcquisition()
            print('接收开关打开')
        except:
            print('error')
            pass

    @pyqtSlot(np.ndarray, int)
    def onReceiveImage(self, image, count):
        print(count)
        qimage = QImage(image.data, image.shape[1], image.shape[0], QImage.Format_RGB888)
        self.imageCanvas.setPixmap(
            QPixmap.fromImage(
                qimage.scaled(
                    self.imageCanvas.size(),
                    Qt.KeepAspectRatio,
                    Qt.SmoothTransformation
                )
            )
        )

if __name__ == '__main__':
    app = QApplication(sys.argv)
    # #print(QStyleFactory.keys())
    app.setStyle('Fusion')
    wnd = MainWindow()
    wnd.setGeometry(
        QStyle.alignedRect(
            Qt.LeftToRight,
            Qt.AlignCenter,
            wnd.size(),
            app.desktop().availableGeometry()
        )
    )
    print('1')
    wnd.show()
    sys.exit(app.exec_())